package com.westa.smallshop.goodssearch;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.daimajia.swipe.SwipeLayout;
import com.westa.smallshop.R;
import com.westa.smallshop.common.BaseListAdapter;
import com.westa.smallshop.data.GoodsItem;
import com.westa.smallshop.util.HttpUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by cy on 10/11/16.
 */

public class GoodsSearchAdapter extends BaseListAdapter<GoodsSearchAdapter.ViewHolder, GoodsItem> {


    private GoodsSearchFragment mGoodsSearchFragment;

    private LayoutInflater mLayoutInflater;

    GoodsSearchAdapter(GoodsSearchFragment goodsSearchFragment) {
        mGoodsSearchFragment = goodsSearchFragment;
        mLayoutInflater = mGoodsSearchFragment.getActivity().getLayoutInflater();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mLayoutInflater.inflate(R.layout.item_goods_search_result, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        GoodsItem goodsItem = getItemObject(position);
        holder.mTvItemGoodsName.setText(goodsItem.getGoods_name());
        holder.mTvItemGoodsDesc.setText(goodsItem.getGoods_desc());
        holder.mTvItemGoodsPrice.setText(mGoodsSearchFragment.getString(R.string.price_format, String.valueOf(goodsItem.getGoods_price())));
        Glide.with(mGoodsSearchFragment)
                .load(HttpUtils.getHost() + goodsItem.getGoods_pic())
                .into(holder.mIvGoodsItemPic);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_item_goods_pic)
        ImageView mIvGoodsItemPic;
        @BindView(R.id.tv_item_goods_name)
        TextView mTvItemGoodsName;
        @BindView(R.id.tv_item_goods_price)
        TextView mTvItemGoodsPrice;
        @BindView(R.id.tv_item_goods_desc)
        TextView mTvItemGoodsDesc;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

    }
}
